package cn.pegasus.teamwork.pegasus.service.impl;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.pegasus.teamwork.pegasus.entity.BussUcenterArea;
import cn.pegasus.teamwork.pegasus.entity.BussUserInfo;
import cn.pegasus.teamwork.pegasus.entity.BussWasherFundstatistics;
import cn.pegasus.teamwork.pegasus.mapper.BussUserInfoMapper;
import cn.pegasus.teamwork.pegasus.service.BussUserInfoService;
import cn.iyizhan.teamwork.base.service.impl.BaseServiceImpl;
import cn.iyizhan.teamwork.base.util.PageHelper;
import cn.iyizhan.teamwork.base.util.PageObject;

/**
 * @author ryan.bian
 * @version
 */
@Service("bussUserInfoService")
public class BussUserInfoServiceImpl extends BaseServiceImpl<BussUserInfo, BussUserInfoMapper>
		implements BussUserInfoService {
	// 注入当前dao对象
	@Autowired
	private BussUserInfoMapper bussUserInfoMapper;

	public BussUserInfoServiceImpl() {
		setMapperClass(BussUserInfoMapper.class, BussUserInfo.class);
	}

	@Override
	public PageObject<BussUserInfo> PageList(Map<String, Object> map) {
		int totalData = bussUserInfoMapper.getTotal(map);
		PageHelper pageHelper = new PageHelper(totalData, map);
		List<BussUserInfo> list = bussUserInfoMapper.findListByPage(pageHelper.getMap());
		PageObject<BussUserInfo> pageObject = pageHelper.getPageObject();
		pageObject.setDataList(list);
		return pageObject;
	}

	@Override
	public void updateUser(long id, Map<String, Object> map) {
		BussUserInfo userInfo = M2O(map);
		userInfo.setUpdateTime(new Date());
		bussUserInfoMapper.updateByEntity(userInfo);

	}

	@Override
	public BussUserInfo findUserInfo(Integer id) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", id);
		return bussUserInfoMapper.findUserInfo(map);
	}

	@Override
	public boolean updateUserPawd(Map<String, Object> map) {
		String userMobile = map.get("userMobile").toString();
		BussUserInfo newuses = new BussUserInfo();
		newuses.setUserMobile(userMobile);

		newuses = bussUserInfoMapper.selectSingle(newuses);
		if (newuses != null) {
			if (map.get("userPassword") != null) {
				newuses.setUserPassword(map.get("userPassword").toString());
			}

			if (map.get("userPaypwd") != null) {
				newuses.setUserPaypwd(map.get("userPaypwd").toString());
			}

			bussUserInfoMapper.updateByEntity(newuses);
			return true;
		}

		return false;
	}
}
